package com.chiao.dao.admin;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.chiao.core.BaseDao;
import com.chiao.entity.admin.Role;

@Repository
public class RoleDao extends BaseDao{
	
	private static final String LIST_ROLE_SQL="select * from role order by sortno";
	private static final String DELETE_ROLE_SQL="DELETE from role WHERE ROLEID=?";
	private static final String ADD_ROLE_SQL="INSERT INTO role(rolename, roledesc, sortno)VALUES (?, ?, ?)";
	private static final String UPDATE_ROLE_SQL="UPDATE role SET rolename=?, roledesc=?, sortno=? WHERE roleid=?";

	public List<Role> listRole(){
		return queryForList(Role.class, LIST_ROLE_SQL);
	}

	public int updateRole(Role r) {
		return update(UPDATE_ROLE_SQL, r.getRolename(),r.getRoledesc(),r.getSortno(),r.getRoleid());
	}

	public int deleteRole(int id) {
		return update(DELETE_ROLE_SQL,id);
	}

	public long addRole(Role r) {
		return saveForGeneratedKey(ADD_ROLE_SQL, "roleid",r.getRolename(),r.getRoledesc(),r.getSortno());
	}
}
